// pages/shopDetail/shopdetail.js
var http = require('../../utils/request');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeList: {
      1: "常温",
      2: "冷藏",
      3:"FF",
      4:"冷冻"
    },
    statusList: {
      1: "短保",
      2: "长保"
    },
    shopDetail: {},
    scancode: "",
    date: "",
    isEmpty:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options && options.type && options.type == "insert") {
      wx.setNavigationBarTitle({title: '手动录入批次'})
    }
    let that = this;
    that.setData({scancode: options.scancode});
    that.getShopDetail();
  },
  getShopDetail() {
    let that = this;
    http.postData('/xiandu/app/v1/get_commInfo_bycode', {
      comm_code: that.data.scancode
    }, (rep) => {
      if (rep.code == 200200) {
        that.setData({shopDetail: rep.data});
      }
      if(Object.keys(rep.data).length == 0){
        that.setData({
          isEmpty:'empty'
        });
      }
    })
  },
  bindDateChange: function (e) {
    this.setData({date: e.detail.value})
  },
  goSubmit() {
    if (!this.data.date) {
      wx.showToast({title: '请选择生产日期', icon: "none"});
      return;
    }
    this.editExprice();
  },
  editExprice(){
    let that = this;
    http.postData('/xiandu/app/v1/create_batch_app', {
      comm_code: that.data.scancode,
      production_date:that.data.date
    }, (rep) => {
      if (rep.code == 200200) {
        wx.showToast({
          title: '录入成功',
          icon: 'success',//当icon：'none'时，没有图标 只有文字
          duration: 2000
        });
        setTimeout(() => {
          wx.reLaunch({url: '/pages/index/index'})
        }, 2000);
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {}
})
